#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int n, a[2233];
int MX, MN, AV;

void *runner_AV(void *param){
    int ans = 0;
    for(int i = 1; i <= n; ++ i) {
        ans = ans + a[i];
    }
    AV = ans / n;
    pthread_exit(0);
}
void *runner_MN(void *param){
    int ans;
    for(int i = 1; i <= n; ++ i) {
        if(i>1) ans = (ans < a[i] ? ans : a[i]);
        else ans = a[i];
    }
    MN = ans;
    pthread_exit(0);
}
void *runner_MX(void *param){
    int ans = 0;
    for(int i = 1; i <= n; ++ i) {
        if(i>1) ans = (ans > a[i] ? ans : a[i]);
        else ans = a[i];
    }
    MX = ans;
    pthread_exit(0);
}
pthread_t tid_av,tid_mn,tid_mx;
pthread_attr_t attr_av,attr_mn,attr_mx;

int main(int argc, char **argv) {
    n = argc - 1;
    for(int i = 1; i < argc; ++ i) {
        a[i] = atoi(argv[i]);
    }
    pthread_attr_init(&attr_av);
    pthread_create(&tid_av,&attr_av,runner_AV,NULL);
    
    pthread_attr_init(&attr_mn);
    pthread_create(&tid_mn,&attr_mn,runner_MN,NULL);
    
    pthread_attr_init(&attr_mx);
    pthread_create(&tid_mx,&attr_mx,runner_MX,NULL);

    if( pthread_join(tid_av,NULL) == true ) {
      printf("av-thread join failed!\n");
    }
    else {
      printf("join av-threads\n");
    }

    if( pthread_join(tid_mn,NULL) == true ) {
      printf("mn-thread join failed!\n");
    }
    else {
      printf("join mn-threads\n");
    }

    if( pthread_join(tid_mx,NULL) == true ) {
      printf("mn-thread join failed!\n");
    }
    else {
      printf("join mn-threads\n");
    }
    printf("AV = %d\n",AV);
    printf("MN = %d\n",MN);
    printf("MX = %d\n",MX);
}